<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perlapio - perl&#39;s IO abstraction interface. - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perlapio">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlapio.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perlapio">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perlapio">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perlapio">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perlapio">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perlapio">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perlapio">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perlapio">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perlapio">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perlapio">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perlapio">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perlapio">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perlapio">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perlapio">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perlapio">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perlapio">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perlapio">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perlapio">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perlapio">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perlapio">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perlapio">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perlapio">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perlapio">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perlapio">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perlapio">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perlapio">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perlapio">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perlapio">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perlapio">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perlapio">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perlapio">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perlapio">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perlapio">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perlapio">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perlapio">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perlapio">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perlapio">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perlapio">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perlapio">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perlapio">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perlapio">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perlapio">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perlapio">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perlapio">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perlapio">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perlapio">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perlapio">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perlapio">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perlapio">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perlapio">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perlapio">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perlapio">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perlapio">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perlapio">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perlapio">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perlapio">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perlapio">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perlapio">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perlapio">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perlapio">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perlapio">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perlapio">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perlapio">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perlapio">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perlapio">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perlapio">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perlapio">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perlapio">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perlapio">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perlapio">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perlapio">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perlapio">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perlapio">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perlapio">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perlapio">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perlapio">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perlapio">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perlapio">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perlapio">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perlapio">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perlapio">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlapio.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perlapio">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perlapio">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perlapio">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perlapio">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perlapio">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perlapio">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perlapio">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perlapio">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perlapio">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perlapio">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perlapio">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perlapio">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perlapio">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perlapio">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perlapio">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perlapio">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perlapio">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perlapio">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perlapio">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perlapio">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perlapio">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perlapio">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perlapio">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perlapio">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perlapio">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perlapio">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perlapio">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perlapio">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perlapio">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perlapio">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perlapio">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perlapio">5.35.1</a>
          <a class="dropdown-item active" href="perlapio.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlapio.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perlapio.html">perlapio</a>
          <div id="more">
            (<a href="perlapio.txt">source</a>,
            <a href="https://metacpan.org/pod/perlapio">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perlapio.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlapio.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlapio.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlapio.html#Co-existence-with-stdio">Co-existence with stdio</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlapio.html#%22Fast-gets%22-Functions">&quot;Fast gets&quot; Functions</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlapio.html#Other-Functions">Other Functions</a>
              </li>
          </ul>

              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perlapio.html#NAME">#</a>NAME</h1>

<p>perlapio - perl&#39;s IO abstraction interface.</p>

<h1 id="SYNOPSIS"><a class="permalink" href="perlapio.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>#define PERLIO_NOT_STDIO 0    /* For co-existence with stdio only */
#include &lt;perlio.h&gt;           /* Usually via #include &lt;perl.h&gt; */

PerlIO *PerlIO_stdin(void);
PerlIO *PerlIO_stdout(void);
PerlIO *PerlIO_stderr(void);

PerlIO *PerlIO_open(const char *path,const char *mode);
PerlIO *PerlIO_fdopen(int fd, const char *mode);
PerlIO *PerlIO_reopen(const char *path, /* deprecated */
        const char *mode, PerlIO *old);
int     PerlIO_close(PerlIO *f);

int     PerlIO_stdoutf(const char *fmt,...)
int     PerlIO_puts(PerlIO *f,const char *string);
int     PerlIO_putc(PerlIO *f,int ch);
SSize_t PerlIO_write(PerlIO *f,const void *buf,size_t numbytes);
int     PerlIO_printf(PerlIO *f, const char *fmt,...);
int     PerlIO_vprintf(PerlIO *f, const char *fmt, va_list args);
int     PerlIO_flush(PerlIO *f);

int     PerlIO_eof(PerlIO *f);
int     PerlIO_error(PerlIO *f);
void    PerlIO_clearerr(PerlIO *f);

int     PerlIO_getc(PerlIO *d);
int     PerlIO_ungetc(PerlIO *f,int ch);
SSize_t PerlIO_read(PerlIO *f, void *buf, size_t numbytes);

int     PerlIO_fileno(PerlIO *f);

void    PerlIO_setlinebuf(PerlIO *f);

Off_t   PerlIO_tell(PerlIO *f);
int     PerlIO_seek(PerlIO *f, Off_t offset, int whence);
void    PerlIO_rewind(PerlIO *f);

int     PerlIO_getpos(PerlIO *f, SV *save);    /* prototype changed */
int     PerlIO_setpos(PerlIO *f, SV *saved);   /* prototype changed */

int     PerlIO_fast_gets(PerlIO *f);
int     PerlIO_has_cntptr(PerlIO *f);
SSize_t PerlIO_get_cnt(PerlIO *f);
char   *PerlIO_get_ptr(PerlIO *f);
void    PerlIO_set_ptrcnt(PerlIO *f, char *ptr, SSize_t count);

int     PerlIO_canset_cnt(PerlIO *f);              /* deprecated */
void    PerlIO_set_cnt(PerlIO *f, int count);      /* deprecated */

int     PerlIO_has_base(PerlIO *f);
char   *PerlIO_get_base(PerlIO *f);
SSize_t PerlIO_get_bufsiz(PerlIO *f);

PerlIO *PerlIO_importFILE(FILE *stdio, const char *mode);
FILE   *PerlIO_exportFILE(PerlIO *f, const char *mode);
FILE   *PerlIO_findFILE(PerlIO *f);
void    PerlIO_releaseFILE(PerlIO *f,FILE *stdio);

int     PerlIO_apply_layers(PerlIO *f, const char *mode,
                                                  const char *layers);
int     PerlIO_binmode(PerlIO *f, int ptype, int imode,
                                                  const char *layers);
void    PerlIO_debug(const char *fmt,...);</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="perlapio.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>Perl&#39;s source code, and extensions that want maximum portability, should use the above functions instead of those defined in ANSI C&#39;s <i>stdio.h</i>. The perl headers (in particular &quot;perlio.h&quot;) will <code>#define</code> them to the I/O mechanism selected at Configure time.</p>

<p>The functions are modeled on those in <i>stdio.h</i>, but parameter order has been &quot;tidied up a little&quot;.</p>

<p><code>PerlIO *</code> takes the place of FILE *. Like FILE * it should be treated as opaque (it is probably safe to assume it is a pointer to something).</p>

<p>There are currently two implementations:</p>

<dl>

<dt id="1.-USE_STDIO"><a class="permalink" href="perlapio.html#1.-USE_STDIO">#</a><a id="1"></a><a id="USE_STDIO"></a>1. USE_STDIO</dt>
<dd>

<p>All above are #define&#39;d to stdio functions or are trivial wrapper functions which call stdio. In this case <i>only</i> PerlIO * is a FILE *. This has been the default implementation since the abstraction was introduced in perl5.003_02.</p>

</dd>
<dt id="2.-USE_PERLIO"><a class="permalink" href="perlapio.html#2.-USE_PERLIO">#</a><a id="2"></a><a id="USE_PERLIO"></a>2. USE_PERLIO</dt>
<dd>

<p>Introduced just after perl5.7.0, this is a re-implementation of the above abstraction which allows perl more control over how IO is done as it decouples IO from the way the operating system and C library choose to do things. For USE_PERLIO PerlIO * has an extra layer of indirection - it is a pointer-to-a-pointer. This allows the PerlIO * to remain with a known value while swapping the implementation around underneath <i>at run time</i>. In this case all the above are true (but very simple) functions which call the underlying implementation.</p>

<p>This is the only implementation for which <code>PerlIO_apply_layers()</code> does anything &quot;interesting&quot;.</p>

<p>The USE_PERLIO implementation is described in <a href="perliol.html">perliol</a>.</p>

</dd>
</dl>

<p>Because &quot;perlio.h&quot; is a thin layer (for efficiency) the semantics of these functions are somewhat dependent on the underlying implementation. Where these variations are understood they are noted below.</p>

<p>Unless otherwise noted, functions return 0 on success, or a negative value (usually <code>EOF</code> which is usually -1) and set <code>errno</code> on error.</p>

<dl>

<dt id="PerlIO_stdin(),-PerlIO_stdout(),-PerlIO_stderr()"><a class="permalink" href="perlapio.html#PerlIO_stdin(),-PerlIO_stdout(),-PerlIO_stderr()">#</a><a id="PerlIO_stdin"></a><a id="PerlIO_stdin-PerlIO_stdout-PerlIO_stderr"></a><b>PerlIO_stdin()</b>, <b>PerlIO_stdout()</b>, <b>PerlIO_stderr()</b></dt>
<dd>

<p>Use these rather than <code>stdin</code>, <code>stdout</code>, <code>stderr</code>. They are written to look like &quot;function calls&quot; rather than variables because this makes it easier to <i>make them</i> function calls if platform cannot export data to loaded modules, or if (say) different &quot;threads&quot; might have different values.</p>

</dd>
<dt id="PerlIO_open(path,-mode),-PerlIO_fdopen(fd,mode)"><a class="permalink" href="perlapio.html#PerlIO_open(path,-mode),-PerlIO_fdopen(fd,mode)">#</a><a id="PerlIO_open"></a><a id="PerlIO_open-path-mode-PerlIO_fdopen-fd-mode"></a><b>PerlIO_open(path, mode)</b>, <b>PerlIO_fdopen(fd,mode)</b></dt>
<dd>

<p>These correspond to fopen()/fdopen() and the arguments are the same. Return <code>NULL</code> and set <code>errno</code> if there is an error. There may be an implementation limit on the number of open handles, which may be lower than the limit on the number of open files - <code>errno</code> may not be set when <code>NULL</code> is returned if this limit is exceeded.</p>

</dd>
<dt id="PerlIO_reopen(path,mode,f)"><a class="permalink" href="perlapio.html#PerlIO_reopen(path,mode,f)">#</a><a id="PerlIO_reopen"></a><a id="PerlIO_reopen-path-mode-f"></a><b>PerlIO_reopen(path,mode,f)</b></dt>
<dd>

<p>While this currently exists in both implementations, perl itself does not use it. <i>As perl does not use it, it is not well tested.</i></p>

<p>Perl prefers to <code>dup</code> the new low-level descriptor to the descriptor used by the existing PerlIO. This may become the behaviour of this function in the future.</p>

</dd>
<dt id="PerlIO_printf(f,fmt,...),-PerlIO_vprintf(f,fmt,a)"><a class="permalink" href="perlapio.html#PerlIO_printf(f,fmt,...),-PerlIO_vprintf(f,fmt,a)">#</a><a id="PerlIO_printf"></a><a id="PerlIO_printf-f-fmt-...-PerlIO_vprintf-f-fmt-a"></a><b>PerlIO_printf(f,fmt,...)</b>, <b>PerlIO_vprintf(f,fmt,a)</b></dt>
<dd>

<p>These are fprintf()/vfprintf() equivalents.</p>

</dd>
<dt id="PerlIO_stdoutf(fmt,...)"><a class="permalink" href="perlapio.html#PerlIO_stdoutf(fmt,...)">#</a><a id="PerlIO_stdoutf"></a><a id="PerlIO_stdoutf-fmt"></a><b>PerlIO_stdoutf(fmt,...)</b></dt>
<dd>

<p>This is printf() equivalent. printf is #defined to this function, so it is (currently) legal to use <code>printf(fmt,...)</code> in perl sources.</p>

</dd>
<dt id="PerlIO_read(f,buf,count),-PerlIO_write(f,buf,count)"><a class="permalink" href="perlapio.html#PerlIO_read(f,buf,count),-PerlIO_write(f,buf,count)">#</a><a id="PerlIO_read"></a><a id="PerlIO_read-f-buf-count-PerlIO_write-f-buf-count"></a><b>PerlIO_read(f,buf,count)</b>, <b>PerlIO_write(f,buf,count)</b></dt>
<dd>

<p>These correspond functionally to fread() and fwrite() but the arguments and return values are different. The PerlIO_read() and PerlIO_write() signatures have been modeled on the more sane low level read() and write() functions instead: The &quot;file&quot; argument is passed first, there is only one &quot;count&quot;, and the return value can distinguish between error and <code>EOF</code>.</p>

<p>Returns a byte count if successful (which may be zero or positive), returns negative value and sets <code>errno</code> on error. Depending on implementation <code>errno</code> may be <code>EINTR</code> if operation was interrupted by a signal.</p>

</dd>
<dt id="PerlIO_close(f)"><a class="permalink" href="perlapio.html#PerlIO_close(f)">#</a><a id="PerlIO_close"></a><a id="PerlIO_close-f"></a><b>PerlIO_close(f)</b></dt>
<dd>

<p>Depending on implementation <code>errno</code> may be <code>EINTR</code> if operation was interrupted by a signal.</p>

</dd>
<dt id="PerlIO_puts(f,s),-PerlIO_putc(f,c)"><a class="permalink" href="perlapio.html#PerlIO_puts(f,s),-PerlIO_putc(f,c)">#</a><a id="PerlIO_puts"></a><a id="PerlIO_puts-f-s-PerlIO_putc-f-c"></a><b>PerlIO_puts(f,s)</b>, <b>PerlIO_putc(f,c)</b></dt>
<dd>

<p>These correspond to fputs() and fputc(). Note that arguments have been revised to have &quot;file&quot; first.</p>

</dd>
<dt id="PerlIO_ungetc(f,c)"><a class="permalink" href="perlapio.html#PerlIO_ungetc(f,c)">#</a><a id="PerlIO_ungetc"></a><a id="PerlIO_ungetc-f-c"></a><b>PerlIO_ungetc(f,c)</b></dt>
<dd>

<p>This corresponds to ungetc(). Note that arguments have been revised to have &quot;file&quot; first. Arranges that next read operation will return the byte <b>c</b>. Despite the implied &quot;character&quot; in the name only values in the range 0..0xFF are defined. Returns the byte <b>c</b> on success or -1 (<code>EOF</code>) on error. The number of bytes that can be &quot;pushed back&quot; may vary, only 1 character is certain, and then only if it is the last character that was read from the handle.</p>

</dd>
<dt id="PerlIO_getc(f)"><a class="permalink" href="perlapio.html#PerlIO_getc(f)">#</a><a id="PerlIO_getc"></a><a id="PerlIO_getc-f"></a><b>PerlIO_getc(f)</b></dt>
<dd>

<p>This corresponds to getc(). Despite the c in the name only byte range 0..0xFF is supported. Returns the character read or -1 (<code>EOF</code>) on error.</p>

</dd>
<dt id="PerlIO_eof(f)"><a class="permalink" href="perlapio.html#PerlIO_eof(f)">#</a><a id="PerlIO_eof"></a><a id="PerlIO_eof-f"></a><b>PerlIO_eof(f)</b></dt>
<dd>

<p>This corresponds to feof(). Returns a true/false indication of whether the handle is at end of file. For terminal devices this may or may not be &quot;sticky&quot; depending on the implementation. The flag is cleared by PerlIO_seek(), or PerlIO_rewind().</p>

</dd>
<dt id="PerlIO_error(f)"><a class="permalink" href="perlapio.html#PerlIO_error(f)">#</a><a id="PerlIO_error"></a><a id="PerlIO_error-f"></a><b>PerlIO_error(f)</b></dt>
<dd>

<p>This corresponds to ferror(). Returns a true/false indication of whether there has been an IO error on the handle.</p>

</dd>
<dt id="PerlIO_fileno(f)"><a class="permalink" href="perlapio.html#PerlIO_fileno(f)">#</a><a id="PerlIO_fileno"></a><a id="PerlIO_fileno-f"></a><b>PerlIO_fileno(f)</b></dt>
<dd>

<p>This corresponds to fileno(), note that on some platforms, the meaning of &quot;fileno&quot; may not match Unix. Returns -1 if the handle has no open descriptor associated with it.</p>

</dd>
<dt id="PerlIO_clearerr(f)"><a class="permalink" href="perlapio.html#PerlIO_clearerr(f)">#</a><a id="PerlIO_clearerr"></a><a id="PerlIO_clearerr-f"></a><b>PerlIO_clearerr(f)</b></dt>
<dd>

<p>This corresponds to clearerr(), i.e., clears &#39;error&#39; and (usually) &#39;eof&#39; flags for the &quot;stream&quot;. Does not return a value.</p>

</dd>
<dt id="PerlIO_flush(f)"><a class="permalink" href="perlapio.html#PerlIO_flush(f)">#</a><a id="PerlIO_flush"></a><a id="PerlIO_flush-f"></a><b>PerlIO_flush(f)</b></dt>
<dd>

<p>This corresponds to fflush(). Sends any buffered write data to the underlying file. If called with <code>NULL</code> this may flush all open streams (or core dump with some USE_STDIO implementations). Calling on a handle open for read only, or on which last operation was a read of some kind may lead to undefined behaviour on some USE_STDIO implementations. The USE_PERLIO (layers) implementation tries to behave better: it flushes all open streams when passed <code>NULL</code>, and attempts to retain data on read streams either in the buffer or by seeking the handle to the current logical position.</p>

</dd>
<dt id="PerlIO_seek(f,offset,whence)"><a class="permalink" href="perlapio.html#PerlIO_seek(f,offset,whence)">#</a><a id="PerlIO_seek"></a><a id="PerlIO_seek-f-offset-whence"></a><b>PerlIO_seek(f,offset,whence)</b></dt>
<dd>

<p>This corresponds to fseek(). Sends buffered write data to the underlying file, or discards any buffered read data, then positions the file descriptor as specified by <b>offset</b> and <b>whence</b> (sic). This is the correct thing to do when switching between read and write on the same handle (see issues with PerlIO_flush() above). Offset is of type <code>Off_t</code> which is a perl Configure value which may not be same as stdio&#39;s <code>off_t</code>.</p>

</dd>
<dt id="PerlIO_tell(f)"><a class="permalink" href="perlapio.html#PerlIO_tell(f)">#</a><a id="PerlIO_tell"></a><a id="PerlIO_tell-f"></a><b>PerlIO_tell(f)</b></dt>
<dd>

<p>This corresponds to ftell(). Returns the current file position, or (Off_t) -1 on error. May just return value system &quot;knows&quot; without making a system call or checking the underlying file descriptor (so use on shared file descriptors is not safe without a PerlIO_seek()). Return value is of type <code>Off_t</code> which is a perl Configure value which may not be same as stdio&#39;s <code>off_t</code>.</p>

</dd>
<dt id="PerlIO_getpos(f,p),-PerlIO_setpos(f,p)"><a class="permalink" href="perlapio.html#PerlIO_getpos(f,p),-PerlIO_setpos(f,p)">#</a><a id="PerlIO_getpos"></a><a id="PerlIO_getpos-f-p-PerlIO_setpos-f-p"></a><b>PerlIO_getpos(f,p)</b>, <b>PerlIO_setpos(f,p)</b></dt>
<dd>

<p>These correspond (loosely) to fgetpos() and fsetpos(). Rather than stdio&#39;s Fpos_t they expect a &quot;Perl Scalar Value&quot; to be passed. What is stored there should be considered opaque. The layout of the data may vary from handle to handle. When not using stdio or if platform does not have the stdio calls then they are implemented in terms of PerlIO_tell() and PerlIO_seek().</p>

</dd>
<dt id="PerlIO_rewind(f)"><a class="permalink" href="perlapio.html#PerlIO_rewind(f)">#</a><a id="PerlIO_rewind"></a><a id="PerlIO_rewind-f"></a><b>PerlIO_rewind(f)</b></dt>
<dd>

<p>This corresponds to rewind(). It is usually defined as being</p>

<pre><code>PerlIO_seek(f,(Off_t)0L, SEEK_SET);
PerlIO_clearerr(f);</code></pre>

</dd>
<dt id="PerlIO_tmpfile()"><a class="permalink" href="perlapio.html#PerlIO_tmpfile()">#</a><a id="PerlIO_tmpfile"></a><b>PerlIO_tmpfile()</b></dt>
<dd>

<p>This corresponds to tmpfile(), i.e., returns an anonymous PerlIO or NULL on error. The system will attempt to automatically delete the file when closed. On Unix the file is usually <code>unlink</code>-ed just after it is created so it does not matter how it gets closed. On other systems the file may only be deleted if closed via PerlIO_close() and/or the program exits via <code>exit</code>. Depending on the implementation there may be &quot;race conditions&quot; which allow other processes access to the file, though in general it will be safer in this regard than ad. hoc. schemes.</p>

</dd>
<dt id="PerlIO_setlinebuf(f)"><a class="permalink" href="perlapio.html#PerlIO_setlinebuf(f)">#</a><a id="PerlIO_setlinebuf"></a><a id="PerlIO_setlinebuf-f"></a><b>PerlIO_setlinebuf(f)</b></dt>
<dd>

<p>This corresponds to setlinebuf(). Does not return a value. What constitutes a &quot;line&quot; is implementation dependent but usually means that writing &quot;\n&quot; flushes the buffer. What happens with things like &quot;this\nthat&quot; is uncertain. (Perl core uses it <i>only</i> when &quot;dumping&quot;; it has nothing to do with $| auto-flush.)</p>

</dd>
</dl>

<h2 id="Co-existence-with-stdio"><a class="permalink" href="perlapio.html#Co-existence-with-stdio">#</a><a id="Co"></a>Co-existence with stdio</h2>

<p>There is outline support for co-existence of PerlIO with stdio. Obviously if PerlIO is implemented in terms of stdio there is no problem. However in other cases then mechanisms must exist to create a FILE * which can be passed to library code which is going to use stdio calls.</p>

<p>The first step is to add this line:</p>

<pre><code class="plaintext">#define PERLIO_NOT_STDIO 0</code></pre>

<p><i>before</i> including any perl header files. (This will probably become the default at some point). That prevents &quot;perlio.h&quot; from attempting to #define stdio functions onto PerlIO functions.</p>

<p>XS code is probably better using &quot;typemap&quot; if it expects FILE * arguments. The standard typemap will be adjusted to comprehend any changes in this area.</p>

<dl>

<dt id="PerlIO_importFILE(f,mode)"><a class="permalink" href="perlapio.html#PerlIO_importFILE(f,mode)">#</a><a id="PerlIO_importFILE"></a><a id="PerlIO_importFILE-f-mode"></a><b>PerlIO_importFILE(f,mode)</b></dt>
<dd>

<p>Used to get a PerlIO * from a FILE *.</p>

<p>The mode argument should be a string as would be passed to fopen/PerlIO_open. If it is NULL then - for legacy support - the code will (depending upon the platform and the implementation) either attempt to empirically determine the mode in which <i>f</i> is open, or use &quot;r+&quot; to indicate a read/write stream.</p>

<p>Once called the FILE * should <i>ONLY</i> be closed by calling <code>PerlIO_close()</code> on the returned PerlIO *.</p>

<p>The PerlIO is set to textmode. Use PerlIO_binmode if this is not the desired mode.</p>

<p>This is <b>not</b> the reverse of PerlIO_exportFILE().</p>

</dd>
<dt id="PerlIO_exportFILE(f,mode)"><a class="permalink" href="perlapio.html#PerlIO_exportFILE(f,mode)">#</a><a id="PerlIO_exportFILE"></a><a id="PerlIO_exportFILE-f-mode"></a><b>PerlIO_exportFILE(f,mode)</b></dt>
<dd>

<p>Given a PerlIO * create a &#39;native&#39; FILE * suitable for passing to code expecting to be compiled and linked with ANSI C <i>stdio.h</i>. The mode argument should be a string as would be passed to fopen/PerlIO_open. If it is NULL then - for legacy support - the FILE * is opened in same mode as the PerlIO *.</p>

<p>The fact that such a FILE * has been &#39;exported&#39; is recorded, (normally by pushing a new :stdio &quot;layer&quot; onto the PerlIO *), which may affect future PerlIO operations on the original PerlIO *. You should not call <code>fclose()</code> on the file unless you call <code>PerlIO_releaseFILE()</code> to disassociate it from the PerlIO *. (Do not use PerlIO_importFILE() for doing the disassociation.)</p>

<p>Calling this function repeatedly will create a FILE * on each call (and will push an :stdio layer each time as well).</p>

</dd>
<dt id="PerlIO_releaseFILE(p,f)"><a class="permalink" href="perlapio.html#PerlIO_releaseFILE(p,f)">#</a><a id="PerlIO_releaseFILE"></a><a id="PerlIO_releaseFILE-p-f"></a><b>PerlIO_releaseFILE(p,f)</b></dt>
<dd>

<p>Calling PerlIO_releaseFILE informs PerlIO that all use of FILE * is complete. It is removed from the list of &#39;exported&#39; FILE *s, and the associated PerlIO * should revert to its original behaviour.</p>

<p>Use this to disassociate a file from a PerlIO * that was associated using PerlIO_exportFILE().</p>

</dd>
<dt id="PerlIO_findFILE(f)"><a class="permalink" href="perlapio.html#PerlIO_findFILE(f)">#</a><a id="PerlIO_findFILE"></a><a id="PerlIO_findFILE-f"></a><b>PerlIO_findFILE(f)</b></dt>
<dd>

<p>Returns a native FILE * used by a stdio layer. If there is none, it will create one with PerlIO_exportFILE. In either case the FILE * should be considered as belonging to PerlIO subsystem and should only be closed by calling <code>PerlIO_close()</code>.</p>

</dd>
</dl>

<h2 id="&quot;Fast-gets&quot;-Functions"><a class="permalink" href="perlapio.html#%22Fast-gets%22-Functions">#</a><a id="Fast-gets-Functions"></a>&quot;Fast gets&quot; Functions</h2>

<p>In addition to standard-like API defined so far above there is an &quot;implementation&quot; interface which allows perl to get at internals of PerlIO. The following calls correspond to the various FILE_xxx macros determined by Configure - or their equivalent in other implementations. This section is really of interest to only those concerned with detailed perl-core behaviour, implementing a PerlIO mapping or writing code which can make use of the &quot;read ahead&quot; that has been done by the IO system in the same way perl does. Note that any code that uses these interfaces must be prepared to do things the traditional way if a handle does not support them.</p>

<dl>

<dt id="PerlIO_fast_gets(f)"><a class="permalink" href="perlapio.html#PerlIO_fast_gets(f)">#</a><a id="PerlIO_fast_gets"></a><a id="PerlIO_fast_gets-f"></a><b>PerlIO_fast_gets(f)</b></dt>
<dd>

<p>Returns true if implementation has all the interfaces required to allow perl&#39;s <code>sv_gets</code> to &quot;bypass&quot; normal IO mechanism. This can vary from handle to handle.</p>

<pre><code class="plaintext">PerlIO_fast_gets(f) = PerlIO_has_cntptr(f) &amp;&amp; \
                      PerlIO_canset_cnt(f) &amp;&amp; \
                      &#39;Can set pointer into buffer&#39;</code></pre>

</dd>
<dt id="PerlIO_has_cntptr(f)"><a class="permalink" href="perlapio.html#PerlIO_has_cntptr(f)">#</a><a id="PerlIO_has_cntptr"></a><a id="PerlIO_has_cntptr-f"></a><b>PerlIO_has_cntptr(f)</b></dt>
<dd>

<p>Implementation can return pointer to current position in the &quot;buffer&quot; and a count of bytes available in the buffer. Do not use this - use PerlIO_fast_gets.</p>

</dd>
<dt id="PerlIO_get_cnt(f)"><a class="permalink" href="perlapio.html#PerlIO_get_cnt(f)">#</a><a id="PerlIO_get_cnt"></a><a id="PerlIO_get_cnt-f"></a><b>PerlIO_get_cnt(f)</b></dt>
<dd>

<p>Return count of readable bytes in the buffer. Zero or negative return means no more bytes available.</p>

</dd>
<dt id="PerlIO_get_ptr(f)"><a class="permalink" href="perlapio.html#PerlIO_get_ptr(f)">#</a><a id="PerlIO_get_ptr"></a><a id="PerlIO_get_ptr-f"></a><b>PerlIO_get_ptr(f)</b></dt>
<dd>

<p>Return pointer to next readable byte in buffer, accessing via the pointer (dereferencing) is only safe if PerlIO_get_cnt() has returned a positive value. Only positive offsets up to value returned by PerlIO_get_cnt() are allowed.</p>

</dd>
<dt id="PerlIO_set_ptrcnt(f,p,c)"><a class="permalink" href="perlapio.html#PerlIO_set_ptrcnt(f,p,c)">#</a><a id="PerlIO_set_ptrcnt"></a><a id="PerlIO_set_ptrcnt-f-p-c"></a><b>PerlIO_set_ptrcnt(f,p,c)</b></dt>
<dd>

<p>Set pointer into buffer, and a count of bytes still in the buffer. Should be used only to set pointer to within range implied by previous calls to <code>PerlIO_get_ptr</code> and <code>PerlIO_get_cnt</code>. The two values <i>must</i> be consistent with each other (implementation may only use one or the other or may require both).</p>

</dd>
<dt id="PerlIO_canset_cnt(f)"><a class="permalink" href="perlapio.html#PerlIO_canset_cnt(f)">#</a><a id="PerlIO_canset_cnt"></a><a id="PerlIO_canset_cnt-f"></a><b>PerlIO_canset_cnt(f)</b></dt>
<dd>

<p>Implementation can adjust its idea of number of bytes in the buffer. Do not use this - use PerlIO_fast_gets.</p>

</dd>
<dt id="PerlIO_set_cnt(f,c)"><a class="permalink" href="perlapio.html#PerlIO_set_cnt(f,c)">#</a><a id="PerlIO_set_cnt"></a><a id="PerlIO_set_cnt-f-c"></a><b>PerlIO_set_cnt(f,c)</b></dt>
<dd>

<p>Obscure - set count of bytes in the buffer. Deprecated. Only usable if PerlIO_canset_cnt() returns true. Currently used in only doio.c to force count less than -1 to -1. Perhaps should be PerlIO_set_empty or similar. This call may actually do nothing if &quot;count&quot; is deduced from pointer and a &quot;limit&quot;. Do not use this - use PerlIO_set_ptrcnt().</p>

</dd>
<dt id="PerlIO_has_base(f)"><a class="permalink" href="perlapio.html#PerlIO_has_base(f)">#</a><a id="PerlIO_has_base"></a><a id="PerlIO_has_base-f"></a><b>PerlIO_has_base(f)</b></dt>
<dd>

<p>Returns true if implementation has a buffer, and can return pointer to whole buffer and its size. Used by perl for <b>-T</b> / <b>-B</b> tests. Other uses would be very obscure...</p>

</dd>
<dt id="PerlIO_get_base(f)"><a class="permalink" href="perlapio.html#PerlIO_get_base(f)">#</a><a id="PerlIO_get_base"></a><a id="PerlIO_get_base-f"></a><b>PerlIO_get_base(f)</b></dt>
<dd>

<p>Return <i>start</i> of buffer. Access only positive offsets in the buffer up to the value returned by PerlIO_get_bufsiz().</p>

</dd>
<dt id="PerlIO_get_bufsiz(f)"><a class="permalink" href="perlapio.html#PerlIO_get_bufsiz(f)">#</a><a id="PerlIO_get_bufsiz"></a><a id="PerlIO_get_bufsiz-f"></a><b>PerlIO_get_bufsiz(f)</b></dt>
<dd>

<p>Return the <i>total number of bytes</i> in the buffer, this is neither the number that can be read, nor the amount of memory allocated to the buffer. Rather it is what the operating system and/or implementation happened to <code>read()</code> (or whatever) last time IO was requested.</p>

</dd>
</dl>

<h2 id="Other-Functions"><a class="permalink" href="perlapio.html#Other-Functions">#</a><a id="Other"></a>Other Functions</h2>

<dl>

<dt id="PerlIO_apply_layers(f,mode,layers)"><a class="permalink" href="perlapio.html#PerlIO_apply_layers(f,mode,layers)">#</a><a id="PerlIO_apply_layers"></a><a id="PerlIO_apply_layers-f-mode-layers"></a>PerlIO_apply_layers(f,mode,layers)</dt>
<dd>

<p>The new interface to the USE_PERLIO implementation. The layers &quot;:crlf&quot; and &quot;:raw&quot; are only ones allowed for other implementations and those are silently ignored. (As of perl5.8 &quot;:raw&quot; is deprecated.) Use PerlIO_binmode() below for the portable case.</p>

</dd>
<dt id="PerlIO_binmode(f,ptype,imode,layers)"><a class="permalink" href="perlapio.html#PerlIO_binmode(f,ptype,imode,layers)">#</a><a id="PerlIO_binmode"></a><a id="PerlIO_binmode-f-ptype-imode-layers"></a>PerlIO_binmode(f,ptype,imode,layers)</dt>
<dd>

<p>The hook used by perl&#39;s <code>binmode</code> operator. <b>ptype</b> is perl&#39;s character for the kind of IO:</p>

<dl>

<dt id="&#39;&lt;&#39;-read"><a class="permalink" href="perlapio.html#&#39;%3C&#39;-read">#</a><a id="read"></a>&#39;&lt;&#39; read</dt>
<dd>

</dd>
<dt id="&#39;&gt;&#39;-write"><a class="permalink" href="perlapio.html#&#39;%3E&#39;-write">#</a><a id="write"></a>&#39;&gt;&#39; write</dt>
<dd>

</dd>
<dt id="&#39;+&#39;-read/write"><a class="permalink" href="perlapio.html#&#39;+&#39;-read/write">#</a><a id="read-write"></a>&#39;+&#39; read/write</dt>
<dd>

</dd>
</dl>

<p><b>imode</b> is <code>O_BINARY</code> or <code>O_TEXT</code>.</p>

<p><b>layers</b> is a string of layers to apply, only &quot;:crlf&quot; makes sense in the non USE_PERLIO case. (As of perl5.8 &quot;:raw&quot; is deprecated in favour of passing NULL.)</p>

<p>Portable cases are:</p>

<pre><code>PerlIO_binmode(f,ptype,O_BINARY,NULL);
and
PerlIO_binmode(f,ptype,O_TEXT,&quot;:crlf&quot;);</code></pre>

<p>On Unix these calls probably have no effect whatsoever. Elsewhere they alter &quot;\n&quot; to CR,LF translation and possibly cause a special text &quot;end of file&quot; indicator to be written or honoured on read. The effect of making the call after doing any IO to the handle depends on the implementation. (It may be ignored, affect any data which is already buffered as well, or only apply to subsequent data.)</p>

</dd>
<dt id="PerlIO_debug(fmt,...)"><a class="permalink" href="perlapio.html#PerlIO_debug(fmt,...)">#</a><a id="PerlIO_debug"></a><a id="PerlIO_debug-fmt"></a>PerlIO_debug(fmt,...)</dt>
<dd>

<p>PerlIO_debug is a printf()-like function which can be used for debugging. No return value. Its main use is inside PerlIO where using real printf, warn() etc. would recursively call PerlIO and be a problem.</p>

<p>PerlIO_debug writes to the file named by $ENV{&#39;PERLIO_DEBUG&#39;} or defaults to stderr if the environment variable is not defined. Typical use might be</p>

<pre><code class="plaintext">Bourne shells (sh, ksh, bash, zsh, ash, ...):
 PERLIO_DEBUG=/tmp/perliodebug.log ./perl -Di somescript some args

Csh/Tcsh:
 setenv PERLIO_DEBUG /tmp/perliodebug.log
 ./perl -Di somescript some args

If you have the &quot;env&quot; utility:
 env PERLIO_DEBUG=/tmp/perliodebug.log ./perl -Di somescript args

Win32:
 set PERLIO_DEBUG=perliodebug.log
 perl -Di somescript some args</code></pre>

<p>On a Perl built without <code>-DDEBUGGING</code>, or when the <code>-Di</code> command-line switch is not specified, or under taint, PerlIO_debug() is a no-op.</p>

</dd>
</dl>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
